<?php

namespace app\index\controller;

use AlipayHelper;
use controller\BasicApi;


/**
 * 支付宝接口口控制器
 * @author Vilson
 */
class AlipayController extends BasicApi{


    public
    function index(){
        $this->success('success Alipay');
    }

    public
    function get_auth_token(){
        $aut_code      = input('auth_code', '');
        $grant_type    = input('grant_type', 'authorization_code');
        $refresh_token = input('refresh_token', '');
        if(empty($grant_type)){
            $this->return_json(4001, '缺少参数：grant_type.');
        }
        require_once 'extend/alipay-sdk/helper/AlipayHelper.php';

        if($grant_type == 'authorization_code'){
            $ret = AlipayHelper::get_auth_token($aut_code);
            $this->return_json($ret);
        }
        if($grant_type == 'refresh_token'){
            $ret = AlipayHelper::refresh_token($refresh_token);
            $this->return_json($ret);
        }

    }


}
